package com.medical.system.converter;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.medical.system.model.bo.UserBO;
import com.medical.system.model.bo.UserFormBO;
import com.medical.system.model.bo.UserProfileBO;
import com.medical.system.model.entity.SysUser;
import com.medical.system.model.form.UserForm;
import com.medical.system.model.vo.UserImportVO;
import com.medical.system.model.vo.UserInfoVO;
import com.medical.system.model.vo.UserPageVO;
import com.medical.system.model.vo.UserProfileVO;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

@Mapper(componentModel = "spring")
public interface UserConverter {

    /**
     * 性别中文字段映射到对应枚举
     * @param bo
     * @return
     */
    @Mappings({
            @Mapping(target = "genderLabel", expression = "java(com.medical.core.base.IBaseEnum.getLabelByValue(bo.getGender(), com.medical.core.enums.GenderEnum.class))")
    })
    UserPageVO bo2Vo(UserBO bo);

    UserForm bo2Form(UserFormBO bo);

    Page<UserPageVO> bo2Vo(Page<UserBO> bo);

    UserForm entity2Form(SysUser entity);

    /**
     * entity2Form的逆向映射
     * @param entity
     * @return
     */
    @InheritInverseConfiguration(name = "entity2Form")
    SysUser form2Entity(UserForm entity);

    /**
     * 用户实体映射为响应用户信息
     * @param entity
     * @return
     */
    @Mapping(source = "id", target = "userId")
    UserInfoVO entity2UserInfoVo(SysUser entity);

    /**
     * 导入实体映射为用户实体
     * @param vo
     * @return
     */
    SysUser importVo2Entity(UserImportVO vo);


    @Mappings({
            @Mapping(target = "genderLabel", expression = "java(com.medical.core.base.IBaseEnum.getLabelByValue(bo.getGender(), com.medical.core.enums.GenderEnum.class))")
    })
    UserProfileVO userProfileBo2Vo(UserProfileBO bo);
}
